summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_device_address_space.h
blob: b4a014c3877bb9419d0f7697f8d92a2a8f5267eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string>

#include "common/common_types.h"
#include "core/hle/kernel/k_page_table.h"
#include "core/hle/kernel/slab_helpers.h"
#include "core/hle/result.h"

namespace Kernel {

class KDeviceAddressSpace final
    : public KAutoObjectWithSlabHeapAndContainer<KDeviceAddressSpace, KAutoObjectWithList> {
    KERNEL_AUTOOBJECT_TRAITS(KDeviceAddressSpace, KAutoObject);

public:
    explicit KDeviceAddressSpace(KernelCore& kernel);
    ~KDeviceAddressSpace();

    Result Initialize(u64 address, u64 size);
    void Finalize() override;

    bool IsInitialized() const override {
        return m_is_initialized;
    }
    static void PostDestroy(uintptr_t arg) {}

    Result Attach(Svc::DeviceName device_name);
    Result Detach(Svc::DeviceName device_name);

    Result MapByForce(KPageTable* page_table, VAddr process_address, size_t size,
                      u64 device_address, u32 option) {
        R_RETURN(this->Map(page_table, process_address, size, device_address, option, false));
    }

    Result MapAligned(KPageTable* page_table, VAddr process_address, size_t size,
                      u64 device_address, u32 option) {
        R_RETURN(this->Map(page_table, process_address, size, device_address, option, true));
    }

    Result Unmap(KPageTable* page_table, VAddr process_address, size_t size, u64 device_address);

    static void Initialize();

private:
    Result Map(KPageTable* page_table, VAddr process_address, size_t size, u64 device_address,
               u32 option, bool is_aligned);

private:
    KLightLock m_lock;
    // KDevicePageTable m_table;
    u64 m_space_address{};
    u64 m_space_size{};
    bool m_is_initialized{};
};

} // namespace Kernel